﻿namespace Pub.Class
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Web;

    public static class HttpResponseExtensions
    {
        public static void Redirect(this HttpResponse response, string urlFormat, params object[] values)
        {
            response.Redirect(urlFormat, true, values);
        }

        public static void Redirect(this HttpResponse response, string urlFormat, bool endResponse, params object[] values)
        {
            string url = string.Format(urlFormat, values);
            response.Redirect(url, endResponse);
        }

        public static void Reload(this HttpResponse response)
        {
            response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
        }

        public static void SetFileNotFound(this HttpResponse response)
        {
            response.SetFileNotFound(true);
        }

        public static void SetFileNotFound(this HttpResponse response, bool endResponse)
        {
            response.SetStatus(0x194, "Not Found", endResponse);
        }

        public static void SetInternalServerError(this HttpResponse response)
        {
            response.SetInternalServerError(true);
        }

        public static void SetInternalServerError(this HttpResponse response, bool endResponse)
        {
            response.SetStatus(500, "Internal Server Error", endResponse);
        }

        public static void SetStatus(this HttpResponse response, int code, string description, bool endResponse)
        {
            response.StatusCode = code;
            response.StatusDescription = description;
            if (endResponse)
            {
                response.End();
            }
        }
    }
}

